<template>
  <div>
    <el-row
      :gutter="15"
      class="main"
      :style="{ margin: '0 auto', width: '100%' }"
    >
      <el-form
        ref="elFormGradeNo"
        :model="dataForm"
        size="small"
        label-width="100px"
        label-position="right"
      >
        <template>
          <el-col :span="24">
            <el-form-item label-width="0">
              <div class="jsbos-common-title">
                <h2>选择题库</h2>
                <div class="jsbos-common-head-right">
                  <el-button icon="el-icon-plus" @click="addQuestionLibs()"
                    >添加试题库
                  </el-button>
                </div>
              </div>
              <el-table
                :data="questionLibs"
                size="mini"
                border
                :span-method="folderSpanMethod"
                :summary-method="getSummaries"
                show-summary
              >
                <el-table-column prop="questionLibName" label="题库名称">
                </el-table-column>
                <el-table-column prop="gradeName" label="试题等级">
                </el-table-column>
                <el-table-column prop="selectTi" label="单选题">
                  <template slot-scope="scope">
                    <div v-if="scope.row.selectTiMax > 0">
                      <el-input-number
                        v-model="scope.row.selectTi"
                        placeholder="题数"
                        size="mini"
                        :step="1"
                        :min="0"
                        :max="scope.row.selectTiMax"
                        controls-position="right"
                        @change="numChange('selectTi', scope.row.gradeId)"
                      />
                      <span style="padding: 0 5px"> ≤ </span>
                      <span>{{ scope.row.selectTiMax }}</span>
                    </div>
                    <span v-else>/</span>
                  </template>
                </el-table-column>
                <el-table-column prop="multiple" label="多选题">
                  <template slot-scope="scope">
                    <div v-if="scope.row.multipleMax > 0">
                      <el-input-number
                        v-model="scope.row.multiple"
                        placeholder="题数"
                        size="mini"
                        :step="1"
                        :min="0"
                        :max="scope.row.multipleMax"
                        controls-position="right"
                        @change="numChange('multiple', scope.row.gradeId)"
                      />
                      <span style="padding: 0 5px"> ≤ </span>
                      <span>{{ scope.row.multipleMax }}</span>
                    </div>
                    <span v-else>/</span>
                  </template>
                </el-table-column>
                <el-table-column prop="determine" label="判断题">
                  <template slot-scope="scope">
                    <div v-if="scope.row.determineMax > 0">
                      <el-input-number
                        v-model="scope.row.determine"
                        placeholder="题数"
                        size="mini"
                        :step="1"
                        :min="0"
                        :max="scope.row.determineMax"
                        controls-position="right"
                        @change="numChange('determine', scope.row.gradeId)"
                      />
                      <span style="padding: 0 5px"> ≤ </span>
                      <span>{{ scope.row.determineMax }}</span>
                    </div>
                    <span v-else>/</span>
                  </template>
                </el-table-column>
                <el-table-column prop="blank" label="填空题">
                  <template slot-scope="scope">
                    <div v-if="scope.row.blankMax > 0">
                      <el-input-number
                        v-model="scope.row.blank"
                        placeholder="题数"
                        size="mini"
                        :step="1"
                        :min="0"
                        :max="scope.row.blankMax"
                        controls-position="right"
                        @change="numChange('blank', scope.row.gradeId)"
                      />
                      <span style="padding: 0 5px"> ≤ </span>
                      <span>{{ scope.row.blankMax }}</span>
                    </div>
                    <span v-else>/</span>
                  </template>
                </el-table-column>
                <el-table-column prop="answers" label="问答题">
                  <template slot-scope="scope">
                    <div v-if="scope.row.answersMax > 0">
                      <el-input-number
                        v-model="scope.row.answers"
                        placeholder="题数"
                        size="mini"
                        :step="1"
                        :min="0"
                        :max="scope.row.answersMax"
                        controls-position="right"
                        @change="numChange('answers', scope.row.gradeId)"
                      />
                      <span style="padding: 0 5px"> ≤ </span>
                      <span>{{ scope.row.answersMax }}</span>
                    </div>
                    <span v-else>/</span>
                  </template>
                </el-table-column>
                <!-- <el-table-column prop="cases" label="案例题">
                  <template slot-scope="scope">
                    <div v-if="scope.row.casesMax > 0">
                      <el-input-number
                        v-model="scope.row.cases"
                        placeholder="题数"
                        size="mini"
                        :step="1"
                        :min="0"
                        :max="scope.row.casesMax"
                        controls-position="right"
                        @change="numChange('cases', scope.row.gradeId)"
                      />
                      <span style="padding: 0 5px"> ≤ </span>
                      <span>{{ scope.row.casesMax }}</span>
                    </div>
                    <span v-else>/</span>
                  </template>
                </el-table-column> -->

                <el-table-column label="操作" width="50">
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="text"
                      class="jsbos-table-delBtn"
                      @click="delQuestionLibs(scope.row.questionLibId)"
                    >
                      删除
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
              <!-- <div class="table-actions" @click="addQuestionLibs()">
                <el-button type="text" icon="el-icon-plus">添加</el-button>
              </div> -->
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label-width="0">
              <div class="jsbos-common-title">
                <h2>设置分值</h2>
              </div>
              <el-table
                :data="questionRules"
                size="mini"
                border
                :span-method="scoreSpanMethod"
                :summary-method="getSummariesScore"
                show-summary
              >
                <el-table-column prop="fullName" label="设置分值">
                </el-table-column>
                <el-table-column prop="gradeName" label="试题等级">
                </el-table-column>
                <el-table-column prop="selectTi" label="单选题" min-width="120">
                  <template slot-scope="scope">
                    <span v-if="scope.row.difficultyGradeId == 'total'">{{
                      scope.row.selectTi
                    }}</span>
                    <el-input-number
                      v-else
                      v-model="scope.row.selectTi"
                      placeholder="分值"
                      :style="{ width: '100%' }"
                      :precision="1"
                      :step="0.5"
                      :min="0"
                      controls-position="right"
                      @change="sumPassScore"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="multiple" label="多选题" width="280">
                  <template slot-scope="scope">
                    <span v-if="scope.row.difficultyGradeId == 'total'">{{
                      scope.row.multiple
                    }}</span>

                    <div v-else>
                      <el-input-number
                        v-model="scope.row.multiple"
                        placeholder="分值"
                        :style="{ width: '100px' }"
                        :precision="1"
                        :step="0.5"
                        :min="0"
                        controls-position="right"
                        @change="sumPassScore"
                      />
                      <span style="padding: 0 5px"> 漏选 </span>
                      <el-input-number
                        v-model="scope.row.missedScore_multiple"
                        placeholder="分值"
                        :style="{ width: '100px' }"
                        :precision="1"
                        :step="0.5"
                        :min="0"
                        :max="scope.row.multiple"
                        controls-position="right"
                        @change="sumPassScore"
                      />
                    </div>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="determine"
                  label="判断题"
                  min-width="120"
                >
                  <template slot-scope="scope">
                    <span v-if="scope.row.difficultyGradeId == 'total'">{{
                      scope.row.determine
                    }}</span>
                    <el-input-number
                      v-else
                      v-model="scope.row.determine"
                      placeholder="分值"
                      :style="{ width: '100%' }"
                      :precision="1"
                      :step="0.5"
                      :min="0"
                      controls-position="right"
                      @change="sumPassScore"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="blank" label="填空题" min-width="120">
                  <template slot-scope="scope">
                    <span v-if="scope.row.difficultyGradeId == 'total'">{{
                      scope.row.blank
                    }}</span>
                    <el-input-number
                      v-else
                      v-model="scope.row.blank"
                      placeholder="分值"
                      :style="{ width: '100%' }"
                      :precision="1"
                      :step="0.5"
                      :min="0"
                      controls-position="right"
                      @change="sumPassScore"
                    />
                  </template>
                </el-table-column>
                <el-table-column prop="answers" label="问答题" min-width="120">
                  <template slot-scope="scope">
                    <span v-if="scope.row.difficultyGradeId == 'total'">{{
                      scope.row.answers
                    }}</span>
                    <el-input-number
                      v-else
                      v-model="scope.row.answers"
                      placeholder="分值"
                      :style="{ width: '100%' }"
                      :precision="1"
                      :step="0.5"
                      :min="0"
                      controls-position="right"
                      @change="sumPassScore"
                    />
                  </template>
                </el-table-column>
                <!-- <el-table-column prop="cases" label="案例题" min-width="120">
                  <template slot-scope="scope">
                    <span v-if="scope.row.difficultyGradeId == 'total'">{{
                      scope.row.cases
                    }}</span>
                    <el-input-number
                      v-else
                      v-model="scope.row.cases"
                      placeholder="分值"
                      :style="{ width: '100%' }"
                      :precision="1"
                      :step="0.5"
                      :min="0"
                      controls-position="right"
                      @change="sumPassScore"
                    />
                  </template>
                </el-table-column> -->
              </el-table>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <div class="jsbos-common-title" style="margin-bottom: 20px">
              <h2>总分与及格线</h2>
            </div>
          </el-col>
          <el-col :span="4">
            <el-form-item label="总分：" prop="myScore">
              <template>
                {{ dataForm.myScore }}
              </template>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="及格线(%)：" prop="passLine">
              <el-input-number
                v-model="dataForm.passLine"
                placeholder="数字文本"
                :max="100"
                :min="0"
                :step="1"
                controls-position="right"
                @change="sumPassScore"
              >
              </el-input-number>
              <span style="color: rgb(140, 140, 140); margin-left: 30px"
                >及格分（{{ dataForm.passScore }}） = 总分（{{
                  dataForm.myScore
                }}） * 及格线（{{ dataForm.passLine }}%）</span
              >
            </el-form-item>
          </el-col>
        </template>
      </el-form>
    </el-row>
    <QuestionLibDialog
      ref="questionLibRef"
      v-if="questionLibVisible"
      :folders="dataForm.folders"
      @table-change="selectQuestionLibChange"
    >
    </QuestionLibDialog>
  </div>
</template>
<script>
import QuestionLibDialog from "@/views/exam/paper/questionLibDialog.vue";

export default {
  components: { QuestionLibDialog },
  props: {
    dataFormRandom: {
      type: Object,
      default: () => {},
    },
    difficultyGradeOptions: {
      type: Array,
      default: () => [],
    },
    gradeRules: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      visible: false,
      questionLibVisible: false,
      paperType: "2", // 1-固定版本 2-随机版本
      questionLibs: [],
      questionRules: [],
      dataForm: this.dataFormRandom,
      myScore: 0,
      rules: {},
      grades: this.difficultyGradeOptions,
      questionTypes: [
        "selectTi",
        "multiple",
        "determine",
        "blank",
        "answers",
        "cases",
      ],
      paperRules: [
        {
          paperId: undefined,
          folderId: undefined,
          questionType: "selectTi",
          difficultyGradeId: undefined,
          questionNum: 0,
          score: 0,
          missedScore: 0,
        },
        {
          paperId: undefined,
          folderId: undefined,
          questionType: "multiple",
          difficultyGradeId: undefined,
          questionNum: 0,
          score: 0,
          missedScore: 0,
        },
        {
          paperId: undefined,
          folderId: undefined,
          questionType: "determine",
          difficultyGradeId: undefined,
          questionNum: 0,
          score: 0,
          missedScore: 0,
        },
        {
          paperId: undefined,
          folderId: undefined,
          questionType: "blank",
          difficultyGradeId: undefined,
          questionNum: 0,
          score: 0,
          missedScore: 0,
        },
        {
          paperId: undefined,
          folderId: undefined,
          questionType: "answers",
          difficultyGradeId: undefined,
          questionNum: 0,
          score: 0,
          missedScore: 0,
        },
        {
          paperId: undefined,
          folderId: undefined,
          questionType: "cases",
          difficultyGradeId: undefined,
          questionNum: 0,
          score: 0,
          missedScore: 0,
        },
      ],
    };
  },
  computed: {},
  watch: {
    dataFormRandom() {
      this.dataForm = this.dataFormRandom;
      this.init();
    },
    difficultyGradeOptions() {
      this.grades = this.difficultyGradeOptions;
    },
  },
  created() {},
  mounted() {},
  methods: {
    init() {
      console.log("this.dataForm", this.dataForm);
      this.setPaperRules();
      this.selectQuestionLibChange(this.dataForm.folderList);
    },
    getPaperRules() {
      let _paperRules = [];
      // 遍历题型评分规则 基础
      this.paperRules.forEach((rule) => {
        // 遍历平铺的题库列表
        this.questionLibs.forEach((folder) => {
          let _paperRule = Object.assign({}, rule); // 复制评分规则
          _paperRule.folderId = folder.questionLibId; // 设置题库id
          _paperRule.difficultyGradeId = folder.gradeId; // 设置试题等级id
          _paperRule.questionNum = folder[rule.questionType]; // 设置题目数量
          // 从平铺的评分规则中找到一样试题等级的分值
          const _obj = this.questionRules.find(
            (obj) => obj.difficultyGradeId == folder.gradeId
          );
          if (_obj) {
            // 设置当前题库-试题等级-题型的分值
            _paperRule.score = _obj[rule.questionType];
            // 设置当前题库-试题等级-题型的漏选分值
            _paperRule.missedScore = _obj["missedScore_" + rule.questionType];
          } else {
            _paperRule.score = 0; // 设置分值
            _paperRule.missedScore = 0; // 设置漏选分值
          }
          // console.log(JSON.stringify(_paperRule));
          _paperRules.push(_paperRule);
        });
      });

      return _paperRules;
    },
    setPaperRules() {
      // 随机试卷-按等级组卷 评分规则
      let _rules = this.gradeRules;
      if (_rules && _rules.length > 0) {
        _rules = _rules;
      } else {
        _rules = this.paperRules;
      }
      // 试题等级
      const _grades = this.grades;
      const _rowspan = _grades.length;
      let rule = {
        fullName: "根据题型和试题等级设置每一种难度的分数", //
        selectTi: 0,
        questionNum_selectTi: 0,
        missedScore_selectTi: 0,
        multiple: 0,
        questionNum_multiple: 0,
        missedScore_multiple: 0,
        determine: 0,
        questionNum_determine: 0,
        missedScore_determine: 0,
        blank: 0,
        questionNum_blank: 0,
        missedScore_blank: 0,
        answers: 0,
        questionNum_answers: 0,
        missedScore_answers: 0,
        cases: 0,
        questionNum_cases: 0,
        missedScore_cases: 0,
      };
      _grades.forEach((obj, idx) => {
        const _difficultyGradeId = obj.id;
        let _questionRule = Object.assign({}, rule);
        // 试题等级平铺
        if (idx == 0) this.$set(_questionRule, "rowspan", _rowspan); // 合并标识和合并的行数
        this.$set(_questionRule, "difficultyGradeId", _difficultyGradeId); // 试题等级id
        this.$set(_questionRule, "gradeName", obj.fullName); // 试题等级名称

        // 从所有评分规则中，获取当前试题等级的规则，进行遍历平铺题型
        let _gradeRules = _rules.filter(
          (item) => item.difficultyGradeId == _difficultyGradeId
        );
        _gradeRules = _gradeRules.length > 0 ? _gradeRules : _rules; // 新增时，试题等级评分规则是空的
        // 当前试题等级-题型出现次数
        const typeCount = _gradeRules.reduce((prev, item) => {
          if (item.questionType in prev) {
            prev[item.questionType]++;
          } else {
            prev[item.questionType] = 1;
          }
          return prev;
        }, {});
        // 当前试题等级-按题型分组求和分值
        const typeScores = _gradeRules.reduce(
          (prev, { questionType, score }) => (
            (prev[questionType] = (prev[questionType] || 0) + score), prev
          ),
          {}
        );
        // 当前试题等级-按题型分组求和漏选分值
        const typeMissedScores = _gradeRules.reduce(
          (prev, { questionType, missedScore }) => (
            (prev[questionType] = (prev[questionType] || 0) + missedScore), prev
          ),
          {}
        );
        // 当前试题等级-按题型分组求和题目数量
        const typeQuestionNums = _gradeRules.reduce(
          (prev, { questionType, questionNum }) => (
            (prev[questionType] = (prev[questionType] || 0) + questionNum), prev
          ),
          {}
        );
        this.questionTypes.forEach((type) => {
          // 当前试题等级及题型-分值
          let typeScore = typeScores[type] / typeCount[type];
          this.$set(_questionRule, type, typeScore);
          // 当前试题等级及题型-漏选分值
          const missedScore_ = "missedScore_" + type;
          let typeMissedScore = typeMissedScores[type] / typeMissedScores[type];
          this.$set(_questionRule, missedScore_, typeMissedScore);
          // 当前试题等级及题型-数量
          const questionNum_ = "questionNum_" + type;
          let typeQuestionNum = typeQuestionNums[type];
          this.$set(_questionRule, questionNum_, typeQuestionNum);
        });
        // console.log(JSON.stringify(_questionRule));
        this.questionRules.push(_questionRule);
      });
    },
    // 计算 及格线
    sumPassScore() {
      let _passLine = this.dataForm.passLine;
      this.dataForm.passLine = _passLine ? _passLine : 0;
      _passLine = new Number(this.dataForm.passLine);
      let _totalScore = this.dataForm.myScore;
      this.dataForm.myScore = _totalScore ? _totalScore : 0;
      _totalScore = new Number(this.dataForm.myScore);
      this.dataForm.passScore = Math.round((_passLine * _totalScore) / 100);
      this.$forceUpdate();
    },
    // 试题数量变更
    numChange(type, gradeId) {
      // console.log(type, gradeId);
      const gradeNums = this.questionLibs.filter(
        (item) => item.gradeId == gradeId
      );
      // console.log("gradeNums", gradeNums);
      let gradeNum = gradeNums.reduce(
        (sum, e) => sum + Number(e[type] || 0),
        0
      );
      // console.log("gradeNum", gradeNum);

      const index = this.questionRules.findIndex(
        (item) => item.difficultyGradeId == gradeId
      );
      const item = this.questionRules.find(
        (item) => item.difficultyGradeId == gradeId
      );
      // console.log("item", JSON.stringify(item));
      this.$set(this.questionRules[index], "questionNum_" + type, gradeNum);
      // console.log(
      //   "this.questionRules[index]",
      //   JSON.stringify(this.questionRules[index])
      // );
    },
    // 添加试题库 弹框
    addQuestionLibs() {
      this.questionLibVisible = true;
      this.$nextTick(() => {
        this.$refs.questionLibRef.initData();
      });
    },
    // 选中试题库 change事件
    selectQuestionLibChange(multipleSelection) {
      if (multipleSelection) {
        // 试题等级
        const _grades = this.grades;
        const _rowspan = _grades.length;
        let _folders = [];
        let _paperFolderList = [];
        let _questionLibs = [];
        multipleSelection.forEach((item) => {
          const _qG = item.questionDifficultyGrades;
          // 平铺题库 题型及试题等级题数
          _grades.forEach((obj, idx) => {
            // 试题等级-单选题数量
            const _selectTi = _qG.selectTi ? _qG.selectTi : {};
            const _selectTiMax = _selectTi[obj.id] ? _selectTi[obj.id] : 0;
            // 试题等级-多选题数量
            const _multiple = _qG.multiple ? _qG.multiple : {};
            const _multipleMax = _multiple[obj.id] ? _multiple[obj.id] : 0;
            // 试题等级-判断题数量
            const _determine = _qG.determine ? _qG.determine : {};
            const _determineMax = _determine[obj.id] ? _determine[obj.id] : 0;
            // 试题等级-填空题数量
            const _blank = _qG.blank ? _qG.blank : {};
            const _blakMax = _blank[obj.id] ? _blank[obj.id] : 0;
            // 试题等级-问答题数量
            const _answers = _qG.answers ? _qG.answers : {};
            const _answersMax = _answers[obj.id] ? _answers[obj.id] : 0;
            // 试题等级-案例题数量
            const _cases = _qG.cases ? _qG.cases : {};
            const _casesMax = _cases[obj.id] ? _cases[obj.id] : 0;
            // 试题等级平铺 和 塞入合并标识
            let _questionLib = {
              paperId: undefined,
              questionLibId: item.id, // 题库id
              questionLibName: item.fullName, // 题库名称
              gradeId: obj.id, // 试题等级id
              gradeName: obj.fullName, // 试题等级名称
              selectTi: 0,
              selectTiMax: _selectTiMax,
              multiple: 0,
              multipleMax: _multipleMax,
              determine: 0,
              determineMax: _determineMax,
              blank: 0,
              blankMax: _blakMax,
              answers: 0,
              answersMax: _answersMax,
              cases: 0,
              casesMax: _casesMax,
            };
            if (idx == 0) {
              // 第一行 塞入合并标识和合并的行数
              this.$set(_questionLib, "rowspan", _rowspan);
            } else {
              // 其他行 平铺数据
              this.$set(_questionLib, "rowspan", undefined);
            }
            if (this.dataForm.rules) {
              const _gradeRules = this.dataForm.rules.filter(
                (item) =>
                  item.difficultyGradeId == _questionLib.gradeId &&
                  item.folderId == _questionLib.questionLibId
              );
              if (_gradeRules) {
                _gradeRules.forEach((obj) => {
                  this.$set(_questionLib, obj.questionType, obj.questionNum);
                });
              }
            }
            _questionLibs.push(_questionLib);
          });
          _paperFolderList.push(item);
          _folders.push(item.id);
        });
        this.questionLibs = _questionLibs;
        this.dataForm.folderList = _paperFolderList;
        this.dataForm.folders = _folders;
      } else {
        this.questionLibs = [];
        this.dataForm.folderList = [];
        this.dataForm.folders = [];
      }
      this.questionLibVisible = false;
    },
    //删除试题库
    delQuestionLibs(questionLibId) {
      this.dataForm.folders = this.dataForm.folders.filter(
        (item) => item !== questionLibId
      );
      this.dataForm.folderList = this.dataForm.folderList.filter(
        (item) => item.questionLibId !== questionLibId
      );
      this.questionLibs = this.questionLibs.filter(
        (item) => item.questionLibId !== questionLibId
      );
    },
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "合计（题）";
          return;
        }
        const values = data.map((item) => Number(item[column.property]));
        if (!values.every((value) => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
        } else {
          sums[index] = "";
        }
      });

      let total = 0;
      sums.forEach((sum) => {
        if (!isNaN(sum)) {
          total += Number(sum);
        }
      });
      sums[1] = total;

      return sums;
    },
    folderSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0 || columnIndex === 8) {
        // 第一列
        if (row.rowspan && row.rowspan >= 1) {
          // 行属性中rowspan存在，并且大于等于1的，开始合并
          return {
            rowspan: row.rowspan, // 合并行数
            colspan: 1, // 合并列数
          };
        } else {
          // 不合并，以下写法等于不操作任何
          return {
            rowspan: 0,
            colspan: 0,
          };
        }
      }
    },
    getSummariesScore(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "合计（分）";
          return;
        }
        const values = data.map((item) => Number(item[column.property]));
        const questionNums = data.map((item) =>
          Number(item["questionNum_" + column.property])
        );
        if (!values.every((value) => isNaN(value))) {
          sums[index] = values.reduce((prev, curr, index) => {
            const value = Number(curr);
            const questionNum = Number(questionNums[index]);
            if (!isNaN(value)) {
              return prev + curr * questionNum;
            } else {
              return prev;
            }
          }, 0);
        } else {
          sums[index] = "";
        }
      });

      let total = 0;
      sums.forEach((sum) => {
        if (!isNaN(sum)) {
          total += Number(sum);
        }
      });
      sums[1] = total;

      this.myScore = total;
      this.dataForm.myScore = total;
      // 计算 及格线
      this.sumPassScore();
      return sums;
    },
    scoreSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        // 第一列
        if (row.rowspan && row.rowspan >= 1) {
          // 行属性中rowspan存在，并且大于等于1的，开始合并
          return {
            rowspan: row.rowspan, // 合并行数
            colspan: 1, // 合并列数
          };
        } else {
          // 不合并，以下写法等于不操作任何
          return {
            rowspan: 0,
            colspan: 0,
          };
        }
      }
    },
  },
};
</script>
